/*
 * @(#)XfsimMouseListener.java        1.0 2000/05/09
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfsim.view.listener;

import java.awt.Component;
import java.awt.event.*;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import xfuzzy.xfsim.view.*;
import xfuzzy.util.XConstants;


/**
 * Controlador de eventos de rat�n de la interfaz gr�fica de Xfsim
 * 
 * @author Francisco Jos� Moreno Velo
 *
 */
public class XfsimMouseListener implements MouseListener {

	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Ventana
	 */
	private Xfsim xfsim;

	/**
	 * Men� desplegable asociado a los eventos de rat�n.
	 */
	private JPopupMenu popup;
	
	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//

	/**
	 * Constructor
	 */
	public XfsimMouseListener(Xfsim xfsim) {
		this.xfsim = xfsim;
		
		String olabel[]= { "Insert new log file", "Insert new plot", 
				"Edit log file/plot", "Remove log file/plot" };
		String ocommand[] = { "InsertLog", "InsertPlot", "Edit", "Remove" };
		popup = new JPopupMenu();
		JMenuItem item[] = new JMenuItem[ocommand.length];
		for(int i=0; i<ocommand.length; i++) {
			item[i] = new JMenuItem(olabel[i]);
			item[i].setActionCommand(ocommand[i]);
			item[i].addActionListener(new XfsimActionListener(xfsim));
			item[i].setFont(XConstants.font);
			popup.add(item[i]);
		}
		
	}

	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Interfaz MouseListener. Acci�n al pulsar el rat�n
	 */
	public void mouseClicked(MouseEvent e) {
		if(e.getClickCount() == 2) xfsim.editOutput();
	}
	
	/**
	 * Interfaz MouseListener. Acci�n al apretar un bot�n del rat�n
	 */
	public void mousePressed(MouseEvent e) {
		if(!e.isPopupTrigger()) return;
		popup.show((Component) e.getSource(), e.getX(), e.getY());
	}
	
	/**
	 * Interfaz MouseListener. Acci�n al soltar un bot�n del rat�n
	 */
	public void mouseReleased(MouseEvent e) {
		if(!e.isPopupTrigger()) return;
		popup.show((Component) e.getSource(), e.getX(), e.getY());
	}
	
	/**
	 * Interfaz MouseListener. Acci�n al entrar en la ventana
	 */
	public void mouseEntered(MouseEvent e) {
	}

	/**
	 * Interfaz MouseListener. Acci�n al salir de la ventana
	 */
	public void mouseExited(MouseEvent e) {
	}
}
